/****************************************************************************
*                                                                           *
* matrepository.cpp														    *
*                                                                           *
* ALaRI 2008												                *
*                                                                           *
****************************************************************************/


/****************************************************************************
* Includes										                            *
****************************************************************************/
#include "matrepository.h"
#include "../../common/property.h"

void CMaterialRepository::init()  
{
	float fltDeltaR = CSimProperty::inst()->getResolution()/100.;
	float fltFreq = CSimProperty::inst()->getFrequency();
	getInstance()->addMaterial(new CMaterial("Vacuum", MakeRgb(0x00, 0x00, 0x00), 
		1.f, 1.f, fltDeltaR, fltFreq));
	getInstance()->addMaterial(new CMaterial("Material1", MakeRgb(0xA5, 0x2A, 0x2A), 
		0.89f, 1.330f, fltDeltaR, fltFreq));
	getInstance()->addMaterial(new CMaterial("Air", MakeRgb(0xAD, 0xD8, 0xED), 
		0.999f, 1.0008f, fltDeltaR, fltFreq));
}

QList<CMaterial*>CMaterialRepository::toQList() const 
{
	return (QList<CMaterial*>::fromStdList(getInstance()->toList()));
}

std::list<CMaterial*>CMaterialRepository::toStdList() const 
{
	return (getInstance()->toList());
}

void CMaterialRepository::addMaterial(CMaterial *pMaterial)
{
	assert(pMaterial != NULL);
	getInstance()->addItem(pMaterial->color(), pMaterial);
}

CMaterial* CMaterialRepository::getMaterial(unsigned int nColor)
{
	return (getInstance()->getItem(nColor));
}

CMaterial* CMaterialRepository::getMaterial(const QString& qStrName)
{
	iterator it = getInstance()->begin();
	while (it != getInstance()->end())
	{
		if ((*it).second->name() == qStrName)
			return ((*it).second);
		*it++;
	}
	return NULL;
}

QList<QString> CMaterialRepository::getQListNames()
{
	QList<QString> qListStrNames;
	iterator it = getInstance()->begin();

	while (it != getInstance()->end())
	{
		qListStrNames.push_back((*it).second->name());
		*it++;
	}
	return qListStrNames;	
}

/****************************************************************************
* End of file																*
****************************************************************************/